<template>
	<view class="login-container">
		<view class="login-header">
			<text class="app-title">购物商城</text>
			<text class="app-subtitle">让购物更简单</text>
		</view>

		<view class="login-form">
			<view class="input-group">
				<input class="input-field" type="text" placeholder="请输入手机号或用户名" v-model="username" />
			</view>
			
			<view class="input-group">
				<input class="input-field" type="password" placeholder="请输入密码" v-model="password" />
			</view>

			<button class="login-btn" @click="handleLogin" :disabled="isLogging">
				{{ isLogging ? '登录中...' : '登录' }}
			</button>

			<view class="register-link">
				<text>还没有账号？</text>
				<text class="link" @click="goToRegister">立即注册</text>
			</view>
		</view>
	</view>
</template>

<script>
	import Navigation from '@/utils/navigation.js';
	
	export default {
		data() {
			return {
				username: '',
				password: '',
				isLogging: false
			}
		},
		onLoad() {
			// 检查是否已登录
			this.checkLoginStatus();
		},
		methods: {
			checkLoginStatus() {
				const token = uni.getStorageSync('userToken');
				if (token) {
					Navigation.goToIndex();
				}
			},
			
			handleLogin() {
				if (!this.username || !this.password) {
					uni.showToast({
						title: '请输入用户名和密码',
						icon: 'none'
					});
					return;
				}
				
				this.isLogging = true;
				
				// 模拟登录
				setTimeout(() => {
					this.isLogging = false;
					
					// 保存登录信息
					const userInfo = {
						id: '1',
						username: this.username,
						token: 'mock_token_' + Date.now()
					};
					
					uni.setStorageSync('userToken', userInfo.token);
					uni.setStorageSync('userInfo', userInfo);
					
					uni.showToast({
						title: '登录成功',
						icon: 'success'
					});
					
					setTimeout(() => {
						Navigation.goToIndex();
					}, 1500);
					
				}, 2000);
			},
			
			goToRegister() {
				uni.showToast({
					title: '注册功能开发中',
					icon: 'none'
				});
			}
		}
	}
</script>

<style scoped>
.login-container {
	min-height: 100vh;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	display: flex;
	flex-direction: column;
	padding: 40rpx;
}

.login-header {
	text-align: center;
	padding: 100rpx 0 80rpx;
}

.app-title {
	font-size: 48rpx;
	font-weight: bold;
	color: white;
	display: block;
	margin-bottom: 20rpx;
}

.app-subtitle {
	font-size: 28rpx;
	color: rgba(255, 255, 255, 0.8);
}

.login-form {
	background: white;
	border-radius: 20rpx;
	padding: 60rpx 40rpx;
}

.input-group {
	margin-bottom: 30rpx;
}

.input-field {
	width: 100%;
	height: 80rpx;
	border: 2rpx solid #eee;
	border-radius: 10rpx;
	padding: 0 20rpx;
	font-size: 28rpx;
	background: #f8f9fa;
}

.login-btn {
	width: 100%;
	height: 90rpx;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	color: white;
	border: none;
	border-radius: 45rpx;
	font-size: 32rpx;
	font-weight: bold;
	margin: 40rpx 0;
}

.login-btn:disabled {
	opacity: 0.7;
}

.register-link {
	text-align: center;
	font-size: 26rpx;
	color: #666;
}

.link {
	color: #667eea;
	margin-left: 10rpx;
}
</style>
